package lib.com.Business.component.login;

import lib.com.Business.dataModel.LoginModel;
import lib.com.Dao.entity.Admin;
import lib.com.Dao.entity.SysAdmin;
import water.com.DaoSupport.DbBase.WaterDaoSupportImp;
import lib.com.Dao.entity.User;
import water.com.DaoSupport.DbBase.WaterIDaoSupport;
import water.com.Ioc.WaterBean;

@WaterBean
public class LoginComponent {

    /**
     * 用户登录组件
     * @param loginModel 用户信息
     * @return boolean
     */
    public boolean login(LoginModel loginModel) throws Exception{
        WaterIDaoSupport<Object,Object> daoSupportImp = WaterDaoSupportImp.getInstance();
        //普通用户登录
        if(loginModel.getUserType().equals("N")){
            User user = new User();
            user.setAccount(loginModel.getAccount());
            user.setPassword(loginModel.getPassword());
            return daoSupportImp.selectOne(user)!=null;
        }
        //图书管理员登录
        if(loginModel.getUserType().equals("B")){
            Admin admin = new Admin();
            admin.setAccount(loginModel.getAccount());
            admin.setPassword(loginModel.getPassword());
            return daoSupportImp.selectOne(admin)!=null;
        }
        //系统管理员登录
        if(loginModel.getUserType().equals("S")){
            SysAdmin admin = new SysAdmin();
            admin.setAccount(loginModel.getAccount());
            admin.setPassword(loginModel.getPassword());
            return daoSupportImp.selectOne(admin)!=null;
        }
        return false;
    }

}
